package cn.samir.sudoku.view;

import cn.samir.sudoku.R;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

public class LoadingDialog {
	Context context;
	AlertDialog.Builder builder;
	AlertDialog alertDialog;
	View view;
	ImageView imageView;
	TextView textView;
	Animation animation;

	public LoadingDialog(Context context) {
		this.context = context;
		builder = new Builder(context);
		view = View.inflate(context, R.layout.loading_dialog, null);
		imageView = (ImageView) view.findViewById(R.id.iv_loading);
		textView = (TextView) view.findViewById(R.id.tv_msg);
		animation = AnimationUtils.loadAnimation(context, R.anim.rotate);
		animation.setInterpolator(new LinearInterpolator());
		builder.setView(view);
		alertDialog = builder.create();
	}

	public void show(String msg) {
		if(!alertDialog.isShowing()){
			textView.setText(msg);
			imageView.startAnimation(animation);
			alertDialog.show();
		}
	}

	public void dismiss() {
		alertDialog.dismiss();
	}
}
